<script setup lang="js">
import {ref} from 'vue'
import {ElMessage, ElMessageBox} from "element-plus";
import {closeOrder} from "@/api/orderList.js";

const props = defineProps({
  closeOrderText: {
    type: Object,
    default: ''
  }
})
const emits = defineEmits(['close', 'closeOrderText'])

const handleConfirmNote = () => {
  if (props.closeOrderText.content == null || props.closeOrderText.content === '') {
    ElMessage.warning('操作备注不能为空！')
  } else {
    ElMessageBox.confirm('确认关闭订单吗？', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      let params = new URLSearchParams()
      params.append('ids', props.closeOrderText.orderIds)
      params.append('note', props.closeOrderText.content)
      closeOrder(params).then(res => {
        ElMessage.success('操作成功！')
        ElMessage.warning(res.data.message)
        emits('close')
      })
    }).catch(() => {
      ElMessage.info('已取消操作')
    })
  }
}


</script>

<template>
  <el-dialog title="关闭订单：" width="500px">
    <el-form v-model="props.closeOrderText" label-width="100px">
      <el-form-item label="订单ID号：">
        <el-input v-model="props.closeOrderText.orderIds"></el-input>
      </el-form-item>
      <el-form-item label="操作备注：">
        <el-input v-model="props.closeOrderText.content" type="textarea" rows="3" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="emits('close')">取 消</el-button>
        <el-button type="primary" @click="handleConfirmNote">确 定</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style scoped lang="scss">

</style>